
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>七牛云存储 | home</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="">
    <meta name="description" content="七牛云存储安装七牛云控件pip install qiniu
django接口获取token12345678910#七牛云from qiniu import Authclass Qiniu(APIView):    def get(self,request):        #声明认证对象 参数（ak,sk）        q = Auth(&#39;lSHiV0YqwAZwm-benIiATiafSQ4-y63Zg1TLmXg3&#39;,&#39;KFZy2dDBwOEHIU2Qmb1v6Kx4C2zvILxkMNDpI057&#39;)        #获取token        token = q.upload_token(&#39;md-admin&#39;...">
    
        <link rel="icon" href="/favicon.ico">
    
    
        
            <link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
        
            <link rel="stylesheet" href="/css/stage.css">
        
            <link rel="stylesheet" href="/css/avatar-bg.css">
        
    
<meta name="generator" content="Hexo 4.2.0"></head>

<body>
<header id="header">
    <div class="menu">
        <i class="fa fa-bars"></i>
    </div>
    <div class="header-main">
        <h1><a href="/">home</a></h1>
    </div>
    <div id="nav">
        <div class="nav-img" id="nav-img"></div>
        <div class="sentences">
            少壮不努力，老大徒伤悲。——《汉乐府·长歌行》
        </div>
    </div>
</header>

<div id="content-outer">
    <div id="content-inner">
        <div class="clearfix">
    <article id="post">
        <h1>七牛云存储</h1>
        <div class="create">
            <span>Created</span>
            
                <time datetime="2020-04-30T02:26:35.000Z">
                    2020-04-30
                </time>
            
            
        </div>
        <h1 id="七牛云存储"><a href="#七牛云存储" class="headerlink" title="七牛云存储"></a>七牛云存储</h1><h2 id="安装七牛云控件"><a href="#安装七牛云控件" class="headerlink" title="安装七牛云控件"></a>安装七牛云控件</h2><p>pip install qiniu</p>
<h2 id="django接口获取token"><a href="#django接口获取token" class="headerlink" title="django接口获取token"></a>django接口获取token</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#七牛云</span></span><br><span class="line"><span class="keyword">from</span> qiniu <span class="keyword">import</span> Auth</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Qiniu</span><span class="params">(APIView)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get</span><span class="params">(self,request)</span>:</span></span><br><span class="line">        <span class="comment">#声明认证对象 参数（ak,sk）</span></span><br><span class="line">        q = Auth(<span class="string">'lSHiV0YqwAZwm-benIiATiafSQ4-y63Zg1TLmXg3'</span>,<span class="string">'KFZy2dDBwOEHIU2Qmb1v6Kx4C2zvILxkMNDpI057'</span>)</span><br><span class="line">        <span class="comment">#获取token</span></span><br><span class="line">        token = q.upload_token(<span class="string">'md-admin'</span>)</span><br><span class="line">        <span class="keyword">return</span> Response(&#123;<span class="string">'code'</span>:<span class="number">200</span>,<span class="string">'token'</span>:token&#125;)</span><br></pre></td></tr></table></figure>
<hr>
<h2 id="vue接口请求图片上传"><a href="#vue接口请求图片上传" class="headerlink" title="vue接口请求图片上传"></a>vue接口请求图片上传</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;table&gt;</span><br><span class="line">        &lt;tr&gt;</span><br><span class="line">            &lt;td&gt;</span><br><span class="line">                七牛用户头像：</span><br><span class="line">            &lt;&#x2F;td&gt;</span><br><span class="line">            &lt;td&gt;</span><br><span class="line">                &lt;input type&#x3D;&quot;file&quot; @change&#x3D;&quot;qiniu&quot;&gt;</span><br><span class="line">            &lt;&#x2F;td&gt;</span><br><span class="line">        &lt;&#x2F;tr&gt;</span><br><span class="line">    &lt;&#x2F;table&gt;</span><br><span class="line">  &lt;&#x2F;div&gt;</span><br><span class="line">&lt;&#x2F;template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script&gt;</span><br><span class="line">export default &#123;</span><br><span class="line">    data () &#123;</span><br><span class="line">        return &#123;</span><br><span class="line">            msg: &quot;这是一个变量&quot;,</span><br><span class="line">            src:&#39;&#39;,</span><br><span class="line">            &#x2F;&#x2F;七牛</span><br><span class="line">            token:&#39;&#39;,</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    &#x2F;&#x2F;钩子函数</span><br><span class="line">    mounted:function()&#123;</span><br><span class="line">        &#x2F;&#x2F;获取token</span><br><span class="line">        this.get_token();</span><br><span class="line">        &#125;,</span><br><span class="line">    methods:&#123;</span><br><span class="line">        get_token:function()&#123;</span><br><span class="line">            this.axios.get(&#39;http:&#x2F;&#x2F;127.0.0.1:8000&#x2F;qiniu&#x2F;&#39;).then(res&#x3D;&gt;&#123;           </span><br><span class="line">                    console.log(res)</span><br><span class="line">                    this.token &#x3D; res.data.token</span><br><span class="line">                    console.log(this.token)</span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;,</span><br><span class="line">        &#x2F;&#x2F;七牛上传</span><br><span class="line">        qiniu:function(e)&#123;</span><br><span class="line">            &#x2F;&#x2F;获取文件</span><br><span class="line">            let file &#x3D; e.target.files[0];</span><br><span class="line">            &#x2F;&#x2F;声明表单</span><br><span class="line">            let param &#x3D; new FormData()    </span><br><span class="line">            param.append(&#39;file&#39;,file,file.name)</span><br><span class="line">            param.append(&#39;token&#39;,this.token)   </span><br><span class="line">            &#x2F;&#x2F;自定义zxios</span><br><span class="line">            const axios_qiniu &#x3D; this.axios.create(&#123;withCredentials:false&#125;)</span><br><span class="line"></span><br><span class="line">            &#x2F;&#x2F;发送请求</span><br><span class="line">            axios_qiniu(&#123;</span><br><span class="line">                method:&#39;POST&#39;,</span><br><span class="line">                url:&#39;http:&#x2F;&#x2F;up-z1.qiniu.com&#39;,</span><br><span class="line">                data:param,</span><br><span class="line">                timeout:30000</span><br><span class="line">            &#125;).then(res&#x3D;&gt;&#123;</span><br><span class="line">                console.log(res)</span><br><span class="line">            &#125;)</span><br><span class="line"></span><br><span class="line">        &#125;,</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">&lt;&#x2F;script&gt;</span><br></pre></td></tr></table></figure>
        <div>
            <ul class="tags-category-list" itemprop="keywords"><li class="tags-category-list-item"><a class="tags-category-list-link" href="/hexo_blog/tags/%E4%BA%91%E5%82%A8%E5%AD%98/" rel="tag">云储存</a></li></ul>
        </div>
        <div class="bottom-line"></div>
        
    <nav id="article-nav">
        
            <a href="/hexo_blog/2020/05/02/%E7%94%BB%E4%B8%AD%E7%94%BB/" id="article-nav-newer" class="article-nav-link-wrap">
        <span class="article-nav-title">
            
                画中画
            
        </span>
                <strong class="article-nav-caption">&gt;</strong>
            </a>
        
        
            <a href="/hexo_blog/2020/04/28/%E7%AC%AC%E4%B8%89%E6%96%B9%E7%99%BB%E9%99%86/" id="article-nav-older" class="article-nav-link-wrap">
                <strong class="article-nav-caption">&lt;</strong>
                <span class="article-nav-title">
                    
                        第三方登陆
                </span>
                
            </a>
        
    </nav>


        
    </article>
    <div id="toc">
        
            <h2>Table of Contents</h2>
            <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#七牛云存储"><span class="toc-number">1.</span> <span class="toc-text">七牛云存储</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#安装七牛云控件"><span class="toc-number">1.1.</span> <span class="toc-text">安装七牛云控件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#django接口获取token"><span class="toc-number">1.2.</span> <span class="toc-text">django接口获取token</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#vue接口请求图片上传"><span class="toc-number">1.3.</span> <span class="toc-text">vue接口请求图片上传</span></a></li></ol></li></ol>
        
    </div>
</div>

    </div>
</div>
<footer id="footer">
    <div id="copyright">&copy; Mr.Song  2020</div>
    <div id="theme">
        Powered by <a href="http://hexo.io" target="_blank" rel="noopener">Hexo</a>. Theme by <a href="https://github.com/markyong/hexo-theme-stage" target="_blank" rel="noopener">Stage</a>
    </div>
</footer>
<script src="/lib/js/waterrippleeffect.min.js"></script>
<script src="/js/header-bg.main.js"></script>

    <script src="/lib/js/smooth-scroll.min.js"></script>
    <script src="/js/toc.main.js"></script>

</body>
</html>
